#include "qTimer.h"

qTimer::qTimer(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);
	this->setWindowTitle("小九幻灯片_qTimer");
	this->setWindowIcon(QIcon(":/images/images/Qicon.jpg"));
	QFont ft("微软雅黑", 15);
	ui.imageLabel->setFont(ft);
	ui.imageLabel->setText("点击start观看小九裸照");

	this->picID = 0;
	this->timer = new QTimer;

	QObject::connect(this->timer, &QTimer::timeout,
		this, &qTimer::timerStartSlot);

}

qTimer::~qTimer()
{}

void qTimer::on_startButton_clicked()
{
	this->timer->start(TIMERID_START);
	this->picID = 0;
}

void qTimer::on_stopButton_clicked()
{
	this->timer->stop();
	QFont ft("微软雅黑", 15);
	ui.imageLabel->setFont(ft);
	ui.imageLabel->setText("点击start观看小九裸照");
}

void qTimer::on_oneTimeButton_clicked()
{
	QTimer::singleShot(1000, this, SLOT(timerStartSlot()));
}

void qTimer::timerStartSlot()
{
	this->picID++;
	if (this->picID == 5)
	{
		this->picID = 1;
	}
	QString strPicPath = ":/images/images/";
	strPicPath += QString::number(this->picID) + ".jpg";
	QImage img;
	img.load(strPicPath);
	ui.imageLabel->setPixmap(QPixmap::fromImage(img));
}
